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: 

String Comparision

Former Member
0 Kudos

See this code and the explaination below

  • Variable declaration

DATA : v_route(36) TYPE C,

V_OPRNUM(4) TYPE C.

*Selection Screen

SELECT-OPTIONS: s_matnr FOR mara-matnr, "MATERIAL Number

s_aufnr FOR afpo-aufnr, "Production Order No

s_oprdes FOR <b>V_ROUTE</b>, "Route - Operation" Description

s_opnum FOR <b>V_OPRNUM</b>. "Operation Number

I will have some data in the internal table which based on the selection criteria.

In that I have one field (opr_descp) which is length 40 Characters.

I need only those recods from the internal table where this <b>V_OPRNUM</b> is equal to that first four characters of the internal table field (opr_descp) and I have do the same thing for <b>V_ROUTE </b> is equal to the internal field ( opr_descp) <b>excluding the first four characters</b> of the same field(opr_descp).

Tell me how write the code using string length or any other way. Send me as example or give me suggestion regarding this.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

loop at itab.

l_index = sy-tabix.

if not itab-opr_descp+0(4) = V_OPRNUM and

not itab-opr_descp+4(36) = V_ROUTE .

delete itab index l_index.

endloop.

22 REPLIES 22

Former Member
0 Kudos

loop at itab.

l_index = sy-tabix.

if not itab-opr_descp+0(4) = V_OPRNUM and

not itab-opr_descp+4(36) = V_ROUTE .

delete itab index l_index.

endloop.

0 Kudos

Hi Chandrasekhar,

in the same logic instead of ""if not itab-opr_descp0(4) = V_OPRNUM"" can I write ""if not itab-opr_descp0(4) <b>in</b> V_OPRNUM"" as I want to compare this field to the range which is given in the selection screen (s_oprdes FOR V_ROUTE) and the same with V_ROUTE as well.

Also pls clarify this as well. This field OPR_DESCP is 40 characters long. in the final output i have split this into and display accordingly.

one thing I have noticed in the date is after first four characters there is space for every entry.

can i write the code like

SPLIT OPR_DESCP AT ' '(SPACE)

or is there any other way

0 Kudos

Hema..u can use <b>in</b> <v_oprnum>.

and while displaying use split itab-opr_descp at ' ' into <> <> .

0 Kudos

i think you can use in clause.

instead you can use <b>in</b> in where clause.

<b>loop at itab where text+0(4) in v_oprnum.</b>

2. to avod space , use condense.

vijay

0 Kudos

yes u can use IN for both

for second question u can use SPLIT as u had mentioned

0 Kudos

HI chandrasekhar

THESE ARE THE DECLARATIONS WHICH I HAVE GIVEN. THE TYPES, INTERNAL TABLE, STRUCUTE AND THE VARIABLES.

  • Types declaration for the table ZWIPSTAT1.

TYPES: BEGIN OF t_zwipstat1,

lotnum TYPE zmes_lot, "MES Lot number

ordernum TYPE aufnr, "Order Number

opr_descp TYPE zoprdescp, "Operation Description

END OF t_zwipstat1.

DATA: i_zwipstat1 TYPE STANDARD TABLE OF t_zwipstat1 INITIAL SIZE 0.

DATA: is_zwipstat1 TYPE t_zwipstat1.

DATA: v_route(36) TYPE C,

V_OPRNUM(4) TYPE N,

V_INDEX TYPE SY-TABIX.

SELECT lotnum

ordernum

opr_descp

INTO TABLE i_zwipstat1

FROM zwipstat

WHERE werks = is_zlhstockoverview-werks

AND ordernum = v_ordernum.

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

v_index = sy-tabix.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN V_OPRNUM AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN V_ROUTE.

DELETE IS_ZWIPSTAT INDEX V_INDEX.

ENDLOOP.

IS THIS CORRECT, IF NOT PLEASE CORRECT ME. ALSO AT THE END I HAVE MOVE ALL THE FIELDS TO THE INTERNAL TABLE I_ZWIPSTAT IS SAME IS I_ZWIPSTAT1.

0 Kudos
* Types declaration for the table ZWIPSTAT1.
TYPES: BEGIN OF t_zwipstat1,
lotnum TYPE zmes_lot, "MES Lot number
ordernum TYPE aufnr, "Order Number
opr_descp TYPE zoprdescp, "Operation Description
END OF t_zwipstat1.

DATA: i_zwipstat1 TYPE STANDARD TABLE OF t_zwipstat1 INITIAL SIZE 0.

DATA: is_zwipstat1 TYPE t_zwipstat1.

DATA: v_route(36) TYPE C,
V_OPRNUM(4) TYPE N, 
V_INDEX TYPE SY-TABIX.


SELECT lotnum
ordernum
opr_descp
INTO TABLE i_zwipstat1
FROM zwipstat
WHERE werks = is_zlhstockoverview-werks
AND ordernum = v_ordernum. 


LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.


v_index = sy-tabix.

if not IS_ZWIPSTAT<b>1</b>-OPR_DESCP+0(4) IN V_OPRNUM AND
NOT IS_ZWIPSTAT<b>1</b>-OPR_DESCP+4(36) IN V_ROUTE.
DELETE I_ZWIPSTAT1<b>1</b> INDEX V_INDEX.
<b>else.
move-corresponding I_ZWIPSTAT1 to I_ZWIPSTAT.
append I_ZWIPSTAT.
endif.</b>
ENDLOOP.

Bold ones are corrections to your code.

vijay

0 Kudos

in ur SELEct,is v_ordern select option or parameter,if it is select option then write IN V_ORDERN instead of = V_ORDERN.

<b>please explain from where u r gettin this field is_zlhstockoverview-werks</b>

SELECT lotnum

ordernum

opr_descp

INTO TABLE i_zwipstat1

FROM zwipstat

WHERE werks = <b>is_zlhstockoverview-werks</b>

AND ordernum <b>= v_ordern</b>

write the loop code like this as u r using workareas,this will modify ur internal table I_ZWIPSTAT1 and no need to write separate code

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN V_OPRNUM AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN V_ROUTE.

<b>DELETE TABLE I_ZWIPSTAT1 from IS_ZWIPSTAT1.</b>

ENDLOOP.

Message was edited by: chandrasekhar jagarlamudi

0 Kudos

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

v_index = sy-tabix.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN V_OPRNUM AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN V_ROUTE.

DELETE <b>I_ZWIPSTAT1</b> INDEX V_INDEX.

<b>else.

append is_zwipstat1 to <last internal table.

endif.</b>

ENDLOOP.

0 Kudos

HI Chandrasekhar.

THIS IS THE COMPLETE CODE.

WHEN I CHECK FOR SYNTAX CHECK IT SAYS THAT V_OPRNUM IS NOT AN INTERNAL TABLE.

PLEASE TELL ME HOW SHOULD I WRITE THE SELECT-OPTIONS STATMENT AS HERE THIS V_OPRNUM IS A LOCAL VARIABLE WHICH I DECLARED AS THE USER WILL ENTER ONLY 4 CHARACTERS IN THE SELECTION SCREEN WHICH IS A PART OF ZWIPSTAT-OPR_DESCP AND THE SAME WITH V_ROUTE.

please check the variable declarations, select-options.

TYPE-POOLS: slis.

----


  • Tables *

  • *

----


TABLES : zlhstockoverview, "Stock Overview Details Table

zwipstat, "WIP Status Table

afpo, "Order item

mara, "General Material Data

marc. "Plant Data for Material

----


  • Types *

  • *

----


  • Types declaration for the table ZLHSTOCKOVERVIEW

TYPES: BEGIN OF t_zlhstockoverview,

werks TYPE werks_d, "Plant

matnr TYPE matnr, "Material Number

dispo TYPE dispo, "MRP controller

dat00 TYPE dat00, "Receipt/Requirements date

extra TYPE extra, "MRP element data

umdat TYPE umdat, "Rescheduling date

ornum TYPE aufnr,

lotnumber TYPE zmes_lot,

END OF t_zlhstockoverview.

  • Types declaration for the table ZWIPSTAT.

TYPES: BEGIN OF t_zwipstat,

lotnum TYPE zmes_lot, "MES Lot number

ordernum TYPE aufnr, "Order Number

opr_descp TYPE zoprdescp, "Operation Description

END OF t_zwipstat.

  • Types declaration for the table ZWIPSTAT1.

TYPES: BEGIN OF t_zwipstat1,

lotnum TYPE zmes_lot, "MES Lot number

ordernum TYPE aufnr, "Order Number

opr_descp TYPE zoprdescp, "Operation Description

END OF t_zwipstat1.

  • Types declaration for the table AFPO.

TYPES: BEGIN OF t_afpo,

aufnr TYPE aufnr, "Order Number

dauat TYPE aufart, "Order Type

psmng TYPE co_psmng, "Order item quantity

END OF t_afpo.

  • Types declaration for the table AFPO.

TYPES: BEGIN OF t_mara,

matnr TYPE matnr, "Material Number

normt TYPE normt, "Industry Standard Description

END OF t_mara.

  • Types declaration for the table FINAL1

TYPES: BEGIN OF t_final1,

ordernum TYPE aufnr,

dauat TYPE afpo-dauat,

matnr TYPE zlhstockoverview-matnr,

normt TYPE mara-normt,

lotnum TYPE zwipstat-lotnum,

psmng TYPE afpo-psmng,

umdat TYPE zlhstockoverview-umdat,

dat00 TYPE zlhstockoverview-dat00,

opr_descp TYPE zwipstat-opr_descp,

END OF t_final1.

  • Types declaration for the table FINAL

TYPES: BEGIN OF t_final,

ordernum TYPE aufnr,

dauat TYPE afpo-dauat,

matnr TYPE zlhstockoverview-matnr,

normt TYPE mara-normt,

lotnum TYPE zwipstat-lotnum,

psmng TYPE afpo-psmng,

umdat TYPE zlhstockoverview-umdat,

dat00 TYPE zlhstockoverview-dat00,

opr_descp TYPE zwipstat-opr_descp,

END OF t_final.

----


  • Internal tables *

  • *

----


DATA: i_zlhstockoverview TYPE STANDARD TABLE OF t_zlhstockoverview

INITIAL SIZE 0,

i_zwipstat TYPE STANDARD TABLE OF t_zwipstat INITIAL SIZE 0,

i_zwipstat1 TYPE STANDARD TABLE OF t_zwipstat1 INITIAL SIZE 0,

i_afpo TYPE STANDARD TABLE OF t_afpo INITIAL SIZE 0,

i_mara TYPE STANDARD TABLE OF t_mara INITIAL SIZE 0,

i_final1 TYPE STANDARD TABLE OF t_final1 INITIAL SIZE 0,

i_final TYPE STANDARD TABLE OF t_final INITIAL SIZE 0.

  • Structurs declaration

DATA: is_zlhstockoverview TYPE t_zlhstockoverview,

is_zwipstat TYPE t_zwipstat,

is_zwipstat1 TYPE t_zwipstat1,

is_afpo TYPE t_afpo,

is_mara TYPE t_mara,

is_final1 TYPE t_final1,

is_final TYPE t_final.

  • Variable declaration

DATA : v_extra TYPE zlhstockoverview-extra,

v_lotnum TYPE zmes_lot,

v_ordernum TYPE aufnr,

<b> v_route(36) TYPE C,

V_OPRNUM(4) TYPE N,

v_index TYPE SY-TABIX.</b>

*Constant declaration.

DATA: c_delb0 TYPE delb0 VALUE 'PrdOrd'.

----


  • Selection-screen *

  • *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .

PARAMETERS: p_werks TYPE marc-werks. "default 'TQT1'. "PLANT

SELECT-OPTIONS: s_matnr FOR mara-matnr, "MATERIAL Number

s_aufnr FOR afpo-aufnr, "Production Order No

<b>P_oprdes FOR V_ROUTE, "Route - Operation Description</b>

<b>P_opnum FOR OPRNUM. "Operation Number</b>

PARAMETERS: p_date TYPE mdez-dat00. "Requirement Date

SELECT-OPTIONS: s_dispo FOR marc-dispo, "MRP Controller

s_normt FOR mara-normt. "EG Number

SELECTION-SCREEN END OF BLOCK b1.

----


  • Start-of-selection *

  • *

----


START-OF-SELECTION.

SELECT werks

matnr

dispo

dat00

extra

umdat

INTO TABLE i_zlhstockoverview

FROM zlhstockoverview

WHERE delb0 = c_delb0

AND werks = p_werks

AND umdat = p_date

OR dat00 = p_date

AND matnr IN s_matnr

AND dispo IN s_dispo.

LOOP AT i_zlhstockoverview INTO is_zlhstockoverview.

MOVE is_zlhstockoverview-extra TO v_extra.

SPLIT v_extra AT '/' INTO v_lotnum v_ordernum.

MOVE v_lotnum TO is_zlhstockoverview-lotnumber.

MOVE v_ordernum TO is_zlhstockoverview-ornum.

APPEND is_zlhstockoverview TO i_zlhstockoverview.

SELECT lotnum

ordernum

opr_descp

INTO TABLE i_zwipstat1

FROM zwipstat

WHERE werks = is_zlhstockoverview-werks

AND ordernum = v_ordernum.

SELECT aufnr

dauat

psmng

INTO TABLE i_afpo

FROM afpo

WHERE aufnr = v_ordernum

AND aufnr IN s_aufnr.

SELECT matnr

normt

INTO TABLE i_mara

FROM mara

WHERE matnr = is_zlhstockoverview-matnr

AND matnr IN s_matnr.

ENDLOOP.

<b>LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

v_index = sy-tabix.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN V_OPRNUM AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN V_ROUTE.

DELETE IS_ZWIPSTAT INDEX V_INDEX.

ENDLOOP.</b>

LOOP AT i_zwipstat INTO is_zwipstat.

READ TABLE i_afpo INTO is_afpo WITH KEY

aufnr = is_zwipstat-lotnum.

MOVE is_afpo-dauat TO is_final1-dauat.

MOVE is_afpo-psmng TO is_final1-psmng.

MOVE is_zwipstat-lotnum TO is_final1-lotnum.

MOVE is_zwipstat-ordernum TO is_final1-ordernum.

MOVE is_zwipstat-opr_descp TO is_final1-opr_descp.

APPEND is_final1 TO i_final1.

ENDLOOP.

LOOP AT i_zlhstockoverview INTO is_zlhstockoverview.

READ TABLE i_final1 INTO is_final1 WITH KEY

lotnum = is_zlhstockoverview-lotnumber.

MOVE is_zlhstockoverview-matnr TO is_final1-matnr.

MOVE is_zlhstockoverview-umdat TO is_final1-umdat.

MOVE is_zlhstockoverview-dat00 TO is_final1-dat00.

APPEND is_final1 TO i_final1.

ENDLOOP.

LOOP AT i_mara INTO is_mara.

READ TABLE i_final1 INTO is_final1 WITH KEY

matnr = is_mara-matnr.

MOVE is_final1-ordernum TO is_final-ordernum.

MOVE is_final1-dauat TO is_final-dauat.

MOVE is_final1-matnr TO is_final-matnr.

MOVE is_final1-lotnum TO is_final-lotnum.

MOVE is_final1-psmng TO is_final-psmng.

MOVE is_final1-umdat TO is_final-umdat.

MOVE is_final1-dat00 TO is_final-dat00.

MOVE is_final1-opr_descp TO is_final-opr_descp.

MOVE is_mara-normt TO is_final-normt.

APPEND is_final TO i_final.

ENDLOOP.

  • Sub routine to display the ALV

PERFORM output_alv.

*&----


*& Form OUTPUT_ALV

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


FORM output_alv .

DATA : it_fieldcat TYPE slis_t_fieldcat_alv,

is_layout TYPE slis_layout_alv.

IF it_fieldcat IS INITIAL.

PERFORM field_fill USING it_fieldcat.

ENDIF.

  • Sub routine to set the layout

PERFORM set_layout USING is_layout.

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IS_LAYOUT = IS_LAYOUT

IT_FIELDCAT = IT_FIELDCAT

tables

t_outtab = I_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

if sy-subrc <> 0.

endif.

ENDFORM. " OUTPUT_ALV

*&----


*& Form FIELD_FILL

*&----


  • text

*----


  • -->P_IT_FIELDCAT text

*----


form FIELD_FILL using PT_FIELDCAT type SLIS_T_FIELDCAT_ALV.

data : LS_FIELDCAT type SLIS_FIELDCAT_ALV,

POS type I value 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'ORDERNUM'.

LS_FIELDCAT-REF_FIELDNAME = 'ORDERNUM'.

LS_FIELDCAT-REF_TABNAME = 'ZWIPSTAT'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'DAUAT'.

LS_FIELDCAT-REF_FIELDNAME = 'DAUAT'.

LS_FIELDCAT-REF_TABNAME = 'AFPO'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-REF_FIELDNAME = 'MATNR'.

LS_FIELDCAT-REF_TABNAME = 'MARA'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'NORMT'.

LS_FIELDCAT-REF_FIELDNAME = 'NORMT'.

LS_FIELDCAT-REF_TABNAME = 'MARA'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'LOTNUM'.

LS_FIELDCAT-REF_FIELDNAME = 'LOTNUM'.

LS_FIELDCAT-REF_TABNAME = 'ZWIPSTAT'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'PSMNG'.

LS_FIELDCAT-REF_FIELDNAME = 'PSMNG'.

LS_FIELDCAT-REF_TABNAME = 'AFPO'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'UMDAT'.

LS_FIELDCAT-REF_FIELDNAME = 'UMDAT'.

LS_FIELDCAT-REF_TABNAME = 'ZLHSTOCKOVERVIEW'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'DAT00'.

LS_FIELDCAT-REF_FIELDNAME = 'DAT00'.

LS_FIELDCAT-REF_TABNAME = 'ZLHSTOCKOVERVIEW'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = ''.

LS_FIELDCAT-SELTEXT_L = TEXT-002.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = ''.

LS_FIELDCAT-SELTEXT_L = TEXT-003.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

ENDFORM. " FIELD_FILL

*&----


*& Form SET_LAYOUT

*&----


  • text

*----


  • -->P_IS_LAYOUT text

*----


form SET_LAYOUT using LS_LAYOUT type SLIS_LAYOUT_ALV.

CLEAR ls_layout.

ls_layout-zebra = 'X'.

ls_layout-colwidth_optimize = 'X'.

ENDFORM. " SET_LAYOUT

0 Kudos

Hi Hema...

dont declare as parameters

parameters:

P_oprdes FOR V_ROUTE, "Route - Operation Description

P_opnum FOR OPRNUM. "Operation Number

correct way:

<b>

select-options:

P_oprdes FOR V_ROUTE, "Route - Operation Description

P_opnum FOR OPRNUM. "Operation Number</b>

0 Kudos

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

v_index = sy-tabix.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN <b>P_opnum</b> AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN<b> P_oprdes</b>.

<b>DELETE I_ZWIPSTAT INDEX V_INDEX.</b>

ENDLOOP.

try these changes...

0 Kudos

Hi Hema,

I don't see a need to change it to select-options. Pl change your IF statement as noted below as both are parameters.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) eq V_OPRNUM AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) eq V_ROUTE.

Regards,

Suresh Datti

0 Kudos

change the code which i made in bold

TYPE-POOLS: slis.

----


  • Tables *

  • *

----


TABLES : zlhstockoverview, "Stock Overview Details Table

zwipstat, "WIP Status Table

afpo, "Order item

mara, "General Material Data

marc. "Plant Data for Material

----


  • Types *

  • *

----


  • Types declaration for the table ZLHSTOCKOVERVIEW

TYPES: BEGIN OF t_zlhstockoverview,

werks TYPE werks_d, "Plant

matnr TYPE matnr, "Material Number

dispo TYPE dispo, "MRP controller

dat00 TYPE dat00, "Receipt/Requirements date

extra TYPE extra, "MRP element data

umdat TYPE umdat, "Rescheduling date

ornum TYPE aufnr,

lotnumber TYPE zmes_lot,

END OF t_zlhstockoverview.

  • Types declaration for the table ZWIPSTAT.

TYPES: BEGIN OF t_zwipstat,

lotnum TYPE zmes_lot, "MES Lot number

ordernum TYPE aufnr, "Order Number

opr_descp TYPE zoprdescp, "Operation Description

END OF t_zwipstat.

  • Types declaration for the table ZWIPSTAT1.

TYPES: BEGIN OF t_zwipstat1,

lotnum TYPE zmes_lot, "MES Lot number

ordernum TYPE aufnr, "Order Number

opr_descp TYPE zoprdescp, "Operation Description

END OF t_zwipstat1.

  • Types declaration for the table AFPO.

TYPES: BEGIN OF t_afpo,

aufnr TYPE aufnr, "Order Number

dauat TYPE aufart, "Order Type

psmng TYPE co_psmng, "Order item quantity

END OF t_afpo.

  • Types declaration for the table AFPO.

TYPES: BEGIN OF t_mara,

matnr TYPE matnr, "Material Number

normt TYPE normt, "Industry Standard Description

END OF t_mara.

  • Types declaration for the table FINAL1

TYPES: BEGIN OF t_final1,

ordernum TYPE aufnr,

dauat TYPE afpo-dauat,

matnr TYPE zlhstockoverview-matnr,

normt TYPE mara-normt,

lotnum TYPE zwipstat-lotnum,

psmng TYPE afpo-psmng,

umdat TYPE zlhstockoverview-umdat,

dat00 TYPE zlhstockoverview-dat00,

opr_descp TYPE zwipstat-opr_descp,

END OF t_final1.

  • Types declaration for the table FINAL

TYPES: BEGIN OF t_final,

ordernum TYPE aufnr,

dauat TYPE afpo-dauat,

matnr TYPE zlhstockoverview-matnr,

normt TYPE mara-normt,

lotnum TYPE zwipstat-lotnum,

psmng TYPE afpo-psmng,

umdat TYPE zlhstockoverview-umdat,

dat00 TYPE zlhstockoverview-dat00,

opr_descp TYPE zwipstat-opr_descp,

END OF t_final.

----


  • Internal tables *

  • *

----


DATA: i_zlhstockoverview TYPE STANDARD TABLE OF t_zlhstockoverview

INITIAL SIZE 0,

i_zwipstat TYPE STANDARD TABLE OF t_zwipstat INITIAL SIZE 0,

i_zwipstat1 TYPE STANDARD TABLE OF t_zwipstat1 INITIAL SIZE 0,

i_afpo TYPE STANDARD TABLE OF t_afpo INITIAL SIZE 0,

i_mara TYPE STANDARD TABLE OF t_mara INITIAL SIZE 0,

i_final1 TYPE STANDARD TABLE OF t_final1 INITIAL SIZE 0,

i_final TYPE STANDARD TABLE OF t_final INITIAL SIZE 0.

  • Structurs declaration

DATA: is_zlhstockoverview TYPE t_zlhstockoverview,

is_zwipstat TYPE t_zwipstat,

is_zwipstat1 TYPE t_zwipstat1,

is_afpo TYPE t_afpo,

is_mara TYPE t_mara,

is_final1 TYPE t_final1,

is_final TYPE t_final.

  • Variable declaration

DATA : v_extra TYPE zlhstockoverview-extra,

v_lotnum TYPE zmes_lot,

v_ordernum TYPE aufnr,

v_route(36) TYPE C,

V_OPRNUM(4) TYPE N,

v_index TYPE SY-TABIX.

*Constant declaration.

DATA: c_delb0 TYPE delb0 VALUE 'PrdOrd'.

----


  • Selection-screen *

  • *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .

PARAMETERS: p_werks TYPE marc-werks. "default 'TQT1'. "PLANT

SELECT-OPTIONS: s_matnr FOR mara-matnr, "MATERIAL Number

s_aufnr FOR afpo-aufnr, "Production Order No

P_oprdes FOR V_ROUTE, "Route - Operation Description

P_opnum FOR <b>v_OPRNUM</b>. "Operation Number

PARAMETERS: p_date TYPE mdez-dat00. "Requirement Date

SELECT-OPTIONS: s_dispo FOR marc-dispo, "MRP Controller

s_normt FOR mara-normt. "EG Number

SELECTION-SCREEN END OF BLOCK b1.

----


  • Start-of-selection *

  • *

----


START-OF-SELECTION.

SELECT werks

matnr

dispo

dat00

extra

umdat

INTO TABLE i_zlhstockoverview

FROM zlhstockoverview

WHERE delb0 = c_delb0

AND werks = p_werks

AND umdat = p_date

OR dat00 = p_date

AND matnr IN s_matnr

AND dispo IN s_dispo.

LOOP AT i_zlhstockoverview INTO is_zlhstockoverview.

MOVE is_zlhstockoverview-extra TO v_extra.

SPLIT v_extra AT '/' INTO v_lotnum v_ordernum.

MOVE v_lotnum TO is_zlhstockoverview-lotnumber.

MOVE v_ordernum TO is_zlhstockoverview-ornum.

APPEND is_zlhstockoverview TO i_zlhstockoverview.

SELECT lotnum

ordernum

opr_descp

INTO TABLE i_zwipstat1

FROM zwipstat

WHERE werks = is_zlhstockoverview-werks

AND ordernum = v_ordernum.

SELECT aufnr

dauat

psmng

INTO TABLE i_afpo

FROM afpo

WHERE aufnr = v_ordernum

AND aufnr IN s_aufnr.

SELECT matnr

normt

INTO TABLE i_mara

FROM mara

WHERE matnr = is_zlhstockoverview-matnr

AND matnr IN s_matnr.

ENDLOOP.

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

v_index = sy-tabix.

<b>if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN P_opnum AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN P_oprdes .</b>

DELETE IS_ZWIPSTAT INDEX V_INDEX.

ENDLOOP.

LOOP AT i_zwipstat INTO is_zwipstat.

READ TABLE i_afpo INTO is_afpo WITH KEY

aufnr = is_zwipstat-lotnum.

MOVE is_afpo-dauat TO is_final1-dauat.

MOVE is_afpo-psmng TO is_final1-psmng.

MOVE is_zwipstat-lotnum TO is_final1-lotnum.

MOVE is_zwipstat-ordernum TO is_final1-ordernum.

MOVE is_zwipstat-opr_descp TO is_final1-opr_descp.

APPEND is_final1 TO i_final1.

ENDLOOP.

LOOP AT i_zlhstockoverview INTO is_zlhstockoverview.

READ TABLE i_final1 INTO is_final1 WITH KEY

lotnum = is_zlhstockoverview-lotnumber.

MOVE is_zlhstockoverview-matnr TO is_final1-matnr.

MOVE is_zlhstockoverview-umdat TO is_final1-umdat.

MOVE is_zlhstockoverview-dat00 TO is_final1-dat00.

APPEND is_final1 TO i_final1.

ENDLOOP.

LOOP AT i_mara INTO is_mara.

READ TABLE i_final1 INTO is_final1 WITH KEY

matnr = is_mara-matnr.

MOVE is_final1-ordernum TO is_final-ordernum.

MOVE is_final1-dauat TO is_final-dauat.

MOVE is_final1-matnr TO is_final-matnr.

MOVE is_final1-lotnum TO is_final-lotnum.

MOVE is_final1-psmng TO is_final-psmng.

MOVE is_final1-umdat TO is_final-umdat.

MOVE is_final1-dat00 TO is_final-dat00.

MOVE is_final1-opr_descp TO is_final-opr_descp.

MOVE is_mara-normt TO is_final-normt.

APPEND is_final TO i_final.

ENDLOOP.

  • Sub routine to display the ALV

PERFORM output_alv.

*&----


*& Form OUTPUT_ALV

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


FORM output_alv .

DATA : it_fieldcat TYPE slis_t_fieldcat_alv,

is_layout TYPE slis_layout_alv.

IF it_fieldcat IS INITIAL.

PERFORM field_fill USING it_fieldcat.

ENDIF.

  • Sub routine to set the layout

PERFORM set_layout USING is_layout.

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IS_LAYOUT = IS_LAYOUT

IT_FIELDCAT = IT_FIELDCAT

tables

t_outtab = I_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

if sy-subrc <> 0.

endif.

ENDFORM. " OUTPUT_ALV

*&----


*& Form FIELD_FILL

*&----


  • text

*----


  • -->P_IT_FIELDCAT text

*----


form FIELD_FILL using PT_FIELDCAT type SLIS_T_FIELDCAT_ALV.

data : LS_FIELDCAT type SLIS_FIELDCAT_ALV,

POS type I value 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'ORDERNUM'.

LS_FIELDCAT-REF_FIELDNAME = 'ORDERNUM'.

LS_FIELDCAT-REF_TABNAME = 'ZWIPSTAT'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'DAUAT'.

LS_FIELDCAT-REF_FIELDNAME = 'DAUAT'.

LS_FIELDCAT-REF_TABNAME = 'AFPO'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-REF_FIELDNAME = 'MATNR'.

LS_FIELDCAT-REF_TABNAME = 'MARA'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'NORMT'.

LS_FIELDCAT-REF_FIELDNAME = 'NORMT'.

LS_FIELDCAT-REF_TABNAME = 'MARA'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'LOTNUM'.

LS_FIELDCAT-REF_FIELDNAME = 'LOTNUM'.

LS_FIELDCAT-REF_TABNAME = 'ZWIPSTAT'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'PSMNG'.

LS_FIELDCAT-REF_FIELDNAME = 'PSMNG'.

LS_FIELDCAT-REF_TABNAME = 'AFPO'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'UMDAT'.

LS_FIELDCAT-REF_FIELDNAME = 'UMDAT'.

LS_FIELDCAT-REF_TABNAME = 'ZLHSTOCKOVERVIEW'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'DAT00'.

LS_FIELDCAT-REF_FIELDNAME = 'DAT00'.

LS_FIELDCAT-REF_TABNAME = 'ZLHSTOCKOVERVIEW'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = ''.

LS_FIELDCAT-SELTEXT_L = TEXT-002.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = ''.

LS_FIELDCAT-SELTEXT_L = TEXT-003.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

ENDFORM. " FIELD_FILL

*&----


*& Form SET_LAYOUT

*&----


  • text

*----


  • -->P_IS_LAYOUT text

*----


form SET_LAYOUT using LS_LAYOUT type SLIS_LAYOUT_ALV.

CLEAR ls_layout.

ls_layout-zebra = 'X'.

ls_layout-colwidth_optimize = 'X'.

ENDFORM. " SET_LAYOUT

0 Kudos

and also change the loop

LOOP AT I_ZWIPSTAT1 INTO IS_ZWIPSTAT1.

v_index = sy-tabix.

if not IS_ZWIPSTAT-OPR_DESCP+0(4) IN V_OPRNUM AND

NOT IS_ZWIPSTAT-OPR_DESCP+4(36) IN V_ROUTE.

DELETE I_ZWIPSTAT1 from IS_ZWIPSTAT.

ENDLOOP.

<b>Try to avoid SELECT statements in LOOP,write FOR ALL ENTRIES</b>

former_member188685
Active Contributor
0 Kudos

Hi,

loop at itab where opr_descp+0(4) = V_OPRNUM
                 and opr_descp+4(36) = V_ROUTE.

**do something...
endloop.

regards

vijay

Former Member
0 Kudos

Hi Hema,

1. We can use COMPARISON OPERATORS for character type fields.

2. CP

This we can use

3. Sample program is : (just copy paste)

We will try to fetch those records

starting with ABCD

4.

REPORT abc.

DATA : BEGIN OF itab OCCURS 0,

f(36) TYPE c,

END OF itab.

*----


itab-f = 'ABCDEFGHI'.

APPEND itab.

itab-f = 'ABCPPPPPP'.

APPEND itab.

itab-f = 'XXXABCDEFGHI'.

APPEND itab.

itab-f = 'ABCDPPPPPP'.

APPEND itab.

itab-f = 'LLLLDDD'.

APPEND itab.

*----


LOOP AT itab WHERE f CP 'ABCD*'.

WRITE 😕 itab-f.

ENDLOOP.

I hope it helps.

Regards,

Amit M.

former_member223537
Active Contributor
0 Kudos

Hi,

eg.

if opr_descp+0(4) eq v_oprnum -- for 1st criteria

if opr_descp+4(36) eq v_route -- for 2nd criteria

Best regards,

Prashant

madan_ullasa
Contributor
0 Kudos

hi hema,

check out this piece of code..

w_charg = t_vbrp_temp-charg+4(4).

IF t_vbrp_temp-vrkme <> 'CV'.

IF w_charg <> 0.

w_fkimg = ( t_vbrp_temp-fkimg DIV w_charg ) .

ENDIF.

w_units = t_vbrp_temp-fkimg - ( w_fkimg * w_charg ) .

ENDIF.

w_case = w_case + w_fkimg .

w_tot_units = w_units + w_tot_units .

in this particular case im considering 4 characters of the field charg from VBRP... i.e

if charg is 'abcd1234jk' , then charg+4(4) gives me a value of '1234'.

This is called as substrings..

hope this is clear to you.

regards,

Madan........

Former Member
0 Kudos

Loop at itab.

l_tabix = sy-tabix.

if itab-opr_descp+0(4) <> v_oprnum or

itab-opr_descp+4(40) <> v_route.

if sy-subrc = 0.

delete itab index l_tabix.

endif.

endloop.

Former Member
0 Kudos

Hi Hema,

If i understood ur problem clearly u want to display only those details of internal table whose <b>desc</b>

field parts (first 4char matches OPNUM) and (rest match desc) of ur selection parameters.

I am giving u an example program.

REPORT yh291_practice1 .

  • Tables declaration

TABLES: mara, afpo.

  • Variable declaration

DATA : v_route(36) TYPE c,

v_oprnum(4) TYPE c.

  • Internal table declaration

DATA:

BEGIN OF itab OCCURS 0,

matnr LIKE mara-matnr,

aufnr LIKE afpo-aufnr,

oprdes(40) TYPE c,

END OF itab.

*Selection Screen

SELECT-OPTIONS:

s_matnr FOR mara-matnr, "MATERIAL Number

s_aufnr FOR afpo-aufnr, "Production Order No

s_oprdes FOR v_route, "Route - Operation" Description

s_opnum FOR v_oprnum. "Operation Number

START-OF-SELECTION.

  • Populating internal table

PERFORM populate_itab.

WRITE:/ 'CONTENTS IN INTERNAL TABLE'.

LOOP AT itab.

WRITE:/ itab-matnr, itab-aufnr, itab-oprdes.

ENDLOOP.

SKIP 3.

WRITE:/ 'CONTENTS IN ITAB FOR CREITERIA'.

WRITE: 's_opnum-LOW = "BRIC" s_opnum-HIGH = "COMP" & '.

WRITE: 's_oprdes-low =" DIST DRIVE" s_oprdes-high = "CLEEN" '.

LOOP AT itab WHERE oprdes0(4) IN s_opnum OR oprdes4 IN s_oprdes.

WRITE:/ itab-matnr, itab-aufnr, itab-oprdes0(4), itab-oprdes4.

ENDLOOP.

&----


*& Form populate_itab

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM populate_itab.

  • Populating internal table

itab-matnr = 'FERT-26'.

itab-aufnr = '0001'.

itab-oprdes = 'COMPUTER'.

APPEND itab.

itab-matnr = 'FERT-43'.

itab-aufnr = '0002'.

itab-oprdes = 'WIRE BEARING'.

APPEND itab.

itab-matnr = 'FERT-46'.

itab-aufnr = '0003'.

itab-oprdes = 'SYSTEM'.

APPEND itab.

itab-matnr = 'FERT-60'.

itab-aufnr = '0004'.

itab-oprdes = 'BICYCLEEN'.

APPEND itab.

itab-matnr = 'FERT-63'.

itab-aufnr = '0005'.

itab-oprdes = 'BRICKS'.

APPEND itab.

itab-matnr = 'FERT-65'.

itab-aufnr = '0006'.

itab-oprdes = 'BICYCLE'.

APPEND itab.

itab-matnr = 'FERT-67'.

itab-aufnr = '0007'.

itab-oprdes = 'HARD DISK DRIVE'.

APPEND itab.

itab-matnr = 'FERT-68'.

itab-aufnr = '0007'.

itab-oprdes = 'RAW MATERIAL'.

APPEND itab.

itab-matnr = 'FERT-71'.

itab-aufnr = '0008'.

itab-oprdes = 'HARD DISK DRIVE'.

APPEND itab.

itab-matnr = 'FERT-73'.

itab-aufnr = '0009'.

itab-oprdes = 'RAW MATERIAL'.

APPEND itab.

itab-matnr = 'FERT-74'.

itab-aufnr = '0010'.

itab-oprdes = 'COMPUTER'.

APPEND itab.

itab-matnr = 'FERT-75'.

itab-aufnr = '0011'.

itab-oprdes = 'HARD DISK DRIVE'.

APPEND itab.

ENDFORM. " populate_itab

HOPE this example serves ur purpose.

bye

Lakshmi

Former Member
0 Kudos

hi hema,

You have a field called opr_descp which is of length 40 characters but you need only the first 4 characters of oper_descp for v_opernum and remaining character for v_route.

My suggestion to your problem is solve your problem at very beginning. i.e i suggest you to have 2 fields with oper_num & oper_route instead of one field

opr_descp.

When you are inserting data into the internal table do

like this...


len type i.
len = strlen( string value of oper_descp ).
......
......
oper_num = string value of oper_descp+0(4).
oper_route = string value of oper_descp+4(len).
.......
.......
append itab.

*if you know that len is 40 you donot need len variable.

Because the advantage of using this is...

1. You need not have to use the 2 variables.

2. Use the oper_num or oper_route fields of itab.

if you want to select a particular field use...

read table itab where itab-oper_num = 'xxxx'. or

read table itab where itab-oper_num = 'xxxx.....xxx'.

Hope it helps.

Regards,

Maheswaran.B