Special Linkage for DB2 Stored Procedure

I try to learn COBOL  a little bit more deeply with VISUAL COBOL,  But I feel hard to understand someone's code like this:

******************************************************

       identification division.
       program-id. gip2trbl.

       environment division.
       configuration section.

       data division.
       working-storage section.
       01 TRBLINP-TYPE          PIC  X(01).  
       01 TRBLINP-SEARCH-DATA   PIC  X(40).

       
       LINKAGE SECTION.                                 
       01 TRBLINP.                                       
           05 TRBLINP-IO-LEN      PIC S9(04) COMP-5.   
           05 TRBLINP-IO-TEXT     PIC X(41).       
       01 OUTDATA PIC X(41).

       PROCEDURE DIVISION USING  TRBLINP, OUTDATA  .
      

        UNSTRING  TRBLINP-IO-TEXT (1:TRBLINP-IO-LEN)
       DELIMITED BY '><'                        
       INTO  TRBLINP-TYPE ,
       TRBLINP-SEARCH-DATA .       
                       
       
        move  TRBLINP-IO-TEXT  to  OUTDATA.    
   
           goback.
           
       end program gip2trbl.

**************************************************************

Then I created DB2 stored procedure on DB2 V10.5

I passed "1><611016007800011"  into stored procedure. 

I expected  TRBLINP-IO-LEN having the real length of the string which I passed  and TRBLINP-IO-TEXT has original string value.

I use out parameter to verify TRBLINP-IO-TEXT.  but I only get "<611016007800011",   not "1><611016007800011"


Could someone explain to me how to make it working correctly ?

Really appreciated.

Parents
  • I think the problem is the parameter that you are passing to the stored procedure and you haven't shown me that yet.

    Can you show me what the actual call looks like to the stored procedure?

    You can define special host variables that handle variable length strings like varchars. They have to be defined like the first parameter in your stored procedure only they require that a level 49 be used for the elementary fields and not 05 as you have specified and then you can reference them by the group item name within your SP call:

    01 TRBLINP.                                      

         49 TRBLINP-IO-LEN      PIC S9(04) COMP-5.  

         49 TRBLINP-IO-TEXT     PIC X(41).      

    If you then set the text field to the data item and the length field to the actual length and use TRBLINP as the parameter name then it should work correctly.

    You cannot simply pass in a literal string to a SP that is expecting a variable length field but you must use a host variable as shown above.

Reply
  • I think the problem is the parameter that you are passing to the stored procedure and you haven't shown me that yet.

    Can you show me what the actual call looks like to the stored procedure?

    You can define special host variables that handle variable length strings like varchars. They have to be defined like the first parameter in your stored procedure only they require that a level 49 be used for the elementary fields and not 05 as you have specified and then you can reference them by the group item name within your SP call:

    01 TRBLINP.                                      

         49 TRBLINP-IO-LEN      PIC S9(04) COMP-5.  

         49 TRBLINP-IO-TEXT     PIC X(41).      

    If you then set the text field to the data item and the length field to the actual length and use TRBLINP as the parameter name then it should work correctly.

    You cannot simply pass in a literal string to a SP that is expecting a variable length field but you must use a host variable as shown above.

Children
No Data