AS400 CALL/CALLB/CALLP区别

CALL/CALLB/CALLP的区别

在这里插入图片描述
https://www.ibm.com/docs/en/i/7.2?topic=operations-call#yycall

使用场景

CALL/CALLB/CALLP 均可用于传统格式rpg,但在free-style下只能使用CALLP

效率

CALLB : 比CALL快5倍
CALLP : 比CALL快100倍

(数据来源于论坛:https://www.mcpressonline.com/forum/forum/programming/rpg/12881-callp-vs-callb)

官方建议无论在哪个场景下使用CALLP :
The recommended way to call a program or procedure (written in any language) is to code a prototyped call.

示例

CALL

*...1....+....2....+....3....+....4....+....5....+....6....+....7....+....
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
 *  The CALL operation calls PROGA and allows PROGA to access
 *  FieldA and FieldB, defined elsewhere. PROGA is run using the content
 *  of FieldA and FieldB.  When PROGA has completed, control
 *  returns to the statement following the last PARM statement.
 *
 *
C                   CALL      'PROGA'
C                   PARM                    FieldA
C                   PARM                    FieldB

CALLB

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
 * Define a procedure pointer
D
D ProcPtr         S               *   PROCPTR INZ(%PADDR('Create_Space'))
D Extern          S             10
D
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
 * The following call linkage would be STATIC
C                   CALLB     'BOUNDPROC'
 * The following call linkage would be DYNAMIC
C                   CALL      Extern
 * The following call linkage would be STATIC, using a procedure pointer
C                   CALLB     ProcPtr

CALLP

  • Calling a Prototyped Program Using CALLP
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
 *-------------------------------------------------------------
 *  This prototype for QCMDEXC defines two parameters:
 *   1- a character field that may be shorter in length
 *      than expected
 *   2- any numeric field
 *-------------------------------------------------------------
D qcmdexc         PR                  extpgm('QCMDEXC')
D   cmd                        200A   options(*varsize) const
D   cmdlen                      15P 5 const

 /FREE
      qcmdexc ('WRKSPLF' : %size ('WRKSPLF'));
 /END-FREE
  • Passing an array parameter using CALLP
* The prototype for the procedure has an array parameter.
D proc            pr
D   parm                        10a   dim(5)  

* An array to pass to the procedure
D array           s             10a   dim(5)  

* Call the procedure, passing the array
C                   callp     proc (array) 
  • Calling a Prototyped Procedure Using CALLP
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
 *=================================================================*
 * CvtToHex - convert input string to hex output string            *
 *=================================================================*
D/COPY MYLIB/QRPGLESRC,CVTHEXPR

 *-----------------------------------------------------------------*
 * Main entry parameters                                           *
 * 1. Input:   string                   character(n)               *
 * 2. Output:  hex string               character(2 * n)           *
 *-----------------------------------------------------------------*
D CvtToHex        PI                    OPDESC
D   InString                 16383      CONST OPTIONS(*VARSIZE)
D   HexString                32766      OPTIONS(*VARSIZE)

 *-----------------------------------------------------------------*
 * Prototype for CEEDOD (Retrieve operational descriptor)          *
 *-----------------------------------------------------------------*
D CEEDOD          PR
D                               10I 0 CONST
D                               10I 0
D                               10I 0
D                               10I 0
D                               10I 0
D                               10I 0
D                               12A   OPTIONS(*OMIT)

 * Parameters passed to CEEDOD
D ParmNum         S             10I 0
D DescType        S             10I 0
D DataType        S             10I 0
D DescInfo1       S             10I 0
D DescInfo2       S             10I 0
D InLen           S             10I 0
D HexLen          S             10I 0
 *-----------------------------------------------------------------*
 * Other fields used by the program                                *
 *-----------------------------------------------------------------*
D HexDigits       C                   CONST('0123456789ABCDEF')
D IntDs           DS
D   IntNum                       5I 0 INZ(0)
D   IntChar                      1    OVERLAY(IntNum:2)
D HexDs           DS
D   HexC1                        1
D   HexC2                        1
D InChar          S              1
D Pos             S              5P 0
D HexPos          S              5P 0

 /FREE
    //-------------------------------------------------------------//
    // Use the operational descriptors to determine the lengths of //
    // the parameters that were passed.                            //
    //-------------------------------------------------------------//
    CEEDOD (1 : DescType : DataType :
                DescInfo1 : DescInfo2 : Inlen : *OMIT);
    CEEDOD (2 : DescType : DataType :
                DescInfo1 : DescInfo2 : HexLen : *OMIT);
 
    //-------------------------------------------------------------//
    // Determine the length to handle (minimum of the input length //
    // and half of the hex length)                                 //
    //-------------------------------------------------------------//
    if InLen > HexLen / 2;
       InLen = HexLen / 2;
    endif;
 
    //-------------------------------------------------------------//
    // For each character in the input string, convert to a 2-byte //
    // hexadecimal representation (for example, '5' --> 'F5')      //
    //-------------------------------------------------------------//
    HexPos = 1;
    for Pos = 1 to InLen;
        InChar = %SUBST(InString : Pos :1);
        exsr GetHex;
        %subst (HexString: HexPos: 2) = HexDs;
        HexPos = HexPos + 2;
    endfor;
 
    return;
 
    //================================================================//
    // GetHex - subroutine to convert 'InChar' to 'HexDs'             //
    // Use division by 16 to separate the two hexadecimal digits.     //
    // The quotient is the first digit, the remainder is the second.  //
    //================================================================//
    begsr GetHex;
       IntChar = InChar;
 
       //-----------------------------------------------------//
       // Use the hexadecimal digit (plus 1) to substring the //
       // list of hexadecimal characters '012...CDEF'.        //
       //-----------------------------------------------------//
       HexC1 = %subst (HexDigits: %div(IntNum:16) + 1: 1);
       HexC2 = %subst (HexDigits: %rem(IntNum:16) + 1: 1);
    endsr;  // GetHex
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yikai945

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值