Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to decode the RFC_BYTE data ? #16

Closed
MinasWang opened this issue Oct 19, 2019 · 2 comments
Closed

how to decode the RFC_BYTE data ? #16

MinasWang opened this issue Oct 19, 2019 · 2 comments

Comments

@MinasWang
Copy link

hello guys:
I am getting fields with type of []bytes when the actual data type in ABAP in RAW byte, and using string() function could not make it a readable format. sometime it become "garbled". And the most funny thing is that when I expecting two returns should be different, but the return bytes is exactly the same.

putting my code as below. I am trying to decode the tasktype. Thanks in advance in case you have any ideas.

========================================
package main

import (
"fmt"
"time"
"encoding/base64"
"github.com/sap/gorfc/gorfc"
)

func abapSystem() gorfc.ConnectionParameter {
return gorfc.ConnectionParameter{
Client: "000",
User: "ddic",
Passwd: "",
Lang: "EN",
Ashost: "",

	Sysnr:     "00",
}

}

func main() {
c, err := gorfc.ConnectionFromParams(abapSystem())

if err != nil{
	fmt.Println(err)
} else{
	fmt.Println("ok")
}
defer c.Close()


end_datetime    := time.Now()
d, _ := time.ParseDuration("10m")
start_datetime  := end_datetime.Add( -d )

r, err := c.Call("SWNC_GET_STATRECS_FRAME", 
		map[string]interface{}{
				"READ_START_DATE": start_datetime,
				"READ_START_TIME": start_datetime,
				"READ_END_DATE": end_datetime,
				"READ_END_TIME": end_datetime,
				// "TASKTYPES_PER_WORKPROCESS": "X",
		   },

		)
if err != nil {
    // err
} else {
    all_recs := r["ALL_STATRECS"].([]interface{})
    for _, recs := range all_recs {
        rec  := recs.(map[string]interface{})
        statrecs := rec["STATRECS"].([]interface{})

        // fmt.Println(statrecs)

        for _, statrec := range statrecs {
            stat  := statrec.(map[string]interface{})
            mainrec := stat["MAINREC"].(map[string]interface{})
            r_datetime :=  mainrec["STARTDATE"].(time.Time).Format("2006-01-02") +" "+ mainrec["STARTTIME"].(time.Time).Format("15:04:05")
            // fmt.Println(mainrec)
            fmt.Println("=======")
            fmt.Println(r_datetime)
            // t1 := hex.EncodeToString( mainrec["TASKTYPE"].([]byte) )
            // t2, _ := hex.DecodeString( t1 )
            // t3 := fmt.Sprintf("%s", t2) 

            input := mainrec["TASKTYPE"].([]byte)

			fmt.Println(input)
			// 演示base64编码
			encodeString := base64.StdEncoding.EncodeToString(input)
			fmt.Println(encodeString)
		
			// 对上面的编码结果进行base64解码
			decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
			if err != nil {
			    // log.Fatalln(err)
			    fmt.Println(err)
			}
			fmt.Println(string(decodeBytes))
            fmt.Println(mainrec["TASKTYPE"].([]byte))
            // fmt.Println(mainrec["ACCOUNT"].(string))
            // fmt.Println(mainrec["REPORT"].(string))
            // fmt.Println(mainrec["TCODE"].(string))
            // fmt.Println(mainrec["ENTRY_ID"].(string))
            fmt.Println("=======")
            
        }
	}
}

}

@bsrdjan
Copy link
Member

bsrdjan commented May 4, 2020

It should work with 0.1.0 release, here the unit-test example

@MinasWang
Copy link
Author

thanks @bsrdjan . I have test it and the result looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants