SAP YARD-athon “Cultivate, Learn & Grow in SAP”

SAPYard presents Yard-athon for all SAP Technical Enthusiasts. This is an opportunity to collaborate, learn and hone our skills.

No knowledge is ever wasted. And we believe, everyone would gain something or other from this Yard-athon. Believe us, no knowledge is small or little.

“Cultivate, Learn & Grow in SAP” is our war cry for this Yard-athon. Heil SAP!!

Objective:

The requirement is to modify the below code snippet using all modern 7.4 ABAP syntax and make it efficient. The idea is to get the Plant and Plant Name into an internal table and print the number of entries in the table as the output.

Hint: Make use of ABAP 7.4 syntaxes and minimize the number of lines of codes.

Prizes:

Best 10 submissions, whom our experienced SAP ABAP Panel choose, would get assured Gifts. We will feature the Winners on our Home Page.

How to participate?

We would suggest you register and write your answer in the comment section but it is not mandatory. You can directly write your Answer in the Comment section below (without registering). Please make sure, your code is activated and we can copy it to our system and execute it as it is.

Number of submissions?

You can submit multiple answers. We would consider the best one from your list.

Below code snippet has to be enhanced to win the Prize.

Please Note:

lt_plant[] internal table needs to have all t001w data and internal table lt_plant_name[] has to have only plant and plant name fields. We need data in both the internal tables.

We want to see the best way to populate both lt_plant[] and lt_plnat_name[]. Assume that, we need entries in both the internal tables for some other business logic down the line in the whole big program.

* Local Type Declaration
TYPES: BEGIN OF lty_werks_name,
plant TYPE werks_d,
name TYPE name1,
END OF lty_werks_name.

* Local Data Declaration
DATA: lt_plant TYPE STANDARD TABLE OF t001w,
ls_plant TYPE t001w,
lv_regio TYPE land1 VALUE 'TX',
lt_plant_name TYPE STANDARD TABLE OF lty_werks_name,
ls_plant_name TYPE lty_werks_name,
lv_count TYPE i.

* Select Plant Info
SELECT * FROM t001w
INTO TABLE lt_plant.
* Sy-subrc check not required

* Loop through and save Plant and Name only
LOOP AT lt_plant INTO ls_plant WHERE regio EQ lv_regio.
ls_plant_name-plant = ls_plant-werks.
ls_plant_name-name = ls_plant-name1.
APPEND ls_plant_name TO lt_plant_name.
ENDLOOP.

* Get the Number of Plants in the Region
DESCRIBE TABLE lt_plant_name LINES lv_count.

* Write a plain output
WRITE: 'Region' , lv_regio, 'has', lv_count, 'Plant(s)'.

Sample Output.

Let the innovative, alternative answers and code keep flowing in. What are you waiting for? Type in your snippets and win your Prize.

Participate now!

Encourage your friends, colleagues and team members to participate as well!!