Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

split field into two variables

Former Member
0 Kudos
922

Hi,

I am comparing a field with two variables where the first four characters of the variable are equal to var1 and rest of the characters are equal to var2.


TYPES: BEGIN OF T_ZWIPSTAT,
        LOTNUM TYPE ZMES_LOT,          "MES LOT NUMBER
      ORDERNUM TYPE AUFNR,             "ORDER NUMBER
     OPR_DESCP TYPE ZOPRDESCP,         "OPERATION DESCRIPTION
     ROUTE(36) TYPE C,
    OPR_DES(4) TYPE C,
       END OF T_ZWIPSTAT.


SELECT LOTNUM
           ORDERNUM
           OPR_DESCP
           FROM ZWIPSTAT
           INTO TABLE  I_ZWIPSTAT1
           FOR ALL ENTRIES IN I_ZLHSTOCKOVERVIEW
           WHERE WERKS = I_ZLHSTOCKOVERVIEW-WERKS
             AND ORDERNUM = I_ZLHSTOCKOVERVIEW-ORNUM.
ENDIF.


LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

  V_INDEX = SY-TABIX.

    IF NOT IS_ZWIPSTAT1-OPR_DESCP+0(4) IN S_OPNUM AND
       NOT IS_ZWIPSTAT1-OPR_DESCP+4(36) IN S_OPRDES.

       DELETE I_ZWIPSTAT1 INDEX V_INDEX.
       ELSE.
       MOVE I_ZWIPSTAT1 TO I_ZWIPSTAT.

    ENDIF.
ENDLOOP.

with the above code i have only those records which i need in the internal table.

My requirement is to split the field ""OPR_DESCP"" and get the first 4 charaters to ""opr_des"" and the rest of the characters to ""route"" as defined in the types statement.

Can any one pls tell how write the code for this and where should I write that.

1 ACCEPTED SOLUTION

sreemsft
Contributor
0 Kudos
270

Hi Hema,

Try this code.


TYPES: BEGIN OF T_ZWIPSTAT,
         LOTNUM TYPE ZMES_LOT,          "MES LOT NUMBER
         ORDERNUM TYPE AUFNR,             "ORDER NUMBER
         OPR_DESCP TYPE ZOPRDESCP,         "OPERATION DESCRIPTION
         ROUTE(36) TYPE C,
         OPR_DES(4) TYPE C,
       END OF T_ZWIPSTAT.

SELECT LOTNUM
       ORDERNUM
       OPR_DESCP
  FROM ZWIPSTAT
  INTO TABLE I_ZWIPSTAT1
   FOR ALL ENTRIES IN I_ZLHSTOCKOVERVIEW
 WHERE WERKS = I_ZLHSTOCKOVERVIEW-WERKS
   AND ORDERNUM = I_ZLHSTOCKOVERVIEW-ORNUM.

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.
  V_INDEX = SY-TABIX.
  I_ZWIPSTAT1-OPR_DESCP+0(4) = IS_ZWIPSTAT1-OPR_DES.
  I_ZWIPSTAT1-OPR_DESCP+4(36) = IS_ZWIPSTAT1-ROUTE.
  MODIFY I_ZWIPSTAT1 FROM IS_ZWIPSTAT1 INDEX V_INDEX.
ENDLOOP.

Before that make sure that your Internal table and Work area has same structure.

Thanks,

Sreekanth G

5 REPLIES 5

Former Member
0 Kudos
270

Hi Hema,

1. opr_des = IS_ZWIPSTAT1-OPR_DESCP+0(4)

route = IS_ZWIPSTAT1-OPR_DESCP+4(36)

regards,

amit m.

Message was edited by: Amit Mittal

jayanthi_jayaraman
Active Contributor
0 Kudos
270

Hi,

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

IS_ZWIPSTAT1-opr_des = IS_ZWIPSTAT1-opr_descp+0(4).

IS_ZWIPSTAT1-route = IS_ZWIPSTAT1-opr_descp+4(36).

modify I_ZWIPSTAT1 from IS_ZWIPSTAT1 index sy-tabix.

ENDLOOP.

Kindly reward points by clikcing the star on the left of reply,if it helps.

former_member188685
Active Contributor
0 Kudos
270
opr_des = IS_ZWIPSTAT1-OPR_DESCP+0(4) .
route = IS_ZWIPSTAT1-OPR_DESCP+4(36) .

this way you can do, if you have any delimiter then you can use split.

regards

vijay

Former Member
0 Kudos
270

Hi Hema,

Here IT is ur internal Table.

Afer getting value of OPR_DESCP in Internal table Use following code :

LOOP AT IT.

IT-OPR_DES = IT-OPR_DESCP+0(4).

IT-ROUTE = IT-OPR_DESCP+4(36).

modify IT.

ENDLOOP.

It surely solve ur problem.

Regards,

Digesh Panchal

sreemsft
Contributor
0 Kudos
271

Hi Hema,

Try this code.


TYPES: BEGIN OF T_ZWIPSTAT,
         LOTNUM TYPE ZMES_LOT,          "MES LOT NUMBER
         ORDERNUM TYPE AUFNR,             "ORDER NUMBER
         OPR_DESCP TYPE ZOPRDESCP,         "OPERATION DESCRIPTION
         ROUTE(36) TYPE C,
         OPR_DES(4) TYPE C,
       END OF T_ZWIPSTAT.

SELECT LOTNUM
       ORDERNUM
       OPR_DESCP
  FROM ZWIPSTAT
  INTO TABLE I_ZWIPSTAT1
   FOR ALL ENTRIES IN I_ZLHSTOCKOVERVIEW
 WHERE WERKS = I_ZLHSTOCKOVERVIEW-WERKS
   AND ORDERNUM = I_ZLHSTOCKOVERVIEW-ORNUM.

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.
  V_INDEX = SY-TABIX.
  I_ZWIPSTAT1-OPR_DESCP+0(4) = IS_ZWIPSTAT1-OPR_DES.
  I_ZWIPSTAT1-OPR_DESCP+4(36) = IS_ZWIPSTAT1-ROUTE.
  MODIFY I_ZWIPSTAT1 FROM IS_ZWIPSTAT1 INDEX V_INDEX.
ENDLOOP.

Before that make sure that your Internal table and Work area has same structure.

Thanks,

Sreekanth G